setGlobalDuration(-1)

a = genSoundTable('ounkmaster.aif')

example = 1

# granulation with pointer rate control
if example == 1:
    granulator(table=a, overlaps=4, pitch=.5)

elif example == 2:
    rando(bus='pt', mini=-3, maxi=4)
    granulator(a, overlaps=8, grainsize=.2, pointerrateVar='pt')

elif example == 3:
    rando(bus='pt', mini=-3, maxi=4)
    randomi(bus='pit', mini=.5, maxi=2, rate=.3)
    granulator(a, overlaps=8, grainsize=.2, pitchVar='pit', pointerrateVar='pt')

elif example == 4:
    rando(bus='pt', mini=-3, maxi=4)
    randomi(bus=['pit1','pit2'], mini=.5, maxi=2, rate=[.3,.5])
    granulator(a, overlaps=8, grainsize=[.2,.4], pitchVar=['pit1','pit2'], pointerrateVar='pt')

# granulation with pointer position control
if example == 5:
    rando(bus='pos', mini=.9, maxi=1.1)    
    granulator2(table=a, overlaps=16, amplitude=.2, pitch=1, pointerpos=.2, pointerposVar='pos')

elif example == 6:
    rando(bus='pos')
    rando(bus='grvar', mini=0.5, maxi=1.5)
    randomi(bus='pit', mini=0.5, maxi=1.5, rate=1)
    granulator2(table=a, overlaps=16, amplitude=.2, pitch=1, pointerpos=1, 
                pitchVar='pit', grainsizeVar='grvar', pointerposVar='pos')

startCsound()